package net.orange.framework.dao;

import java.util.HashMap;
import java.util.Map;

import net.orange.architecture.db.ICacheDao;
import net.orange.architecture.db.PositiveCacheDao;
import net.orange.architecture.db.IObjectManager;
import net.orange.architecture.model.BaseValueObject;
import net.orange.framework.model.Resource;

/**
 * The IResourceDao implement in Hibernate and cache in the memory.
 */
public class CacheResourceDao extends PositiveCacheDao implements ICacheDao {

	/**
	 * Cache hash Map for resource.
	 */
	private static Map<Object, Object> cache = new HashMap<Object, Object>();

	/**
	 * Constructor with the target dao.
	 * 
	 * @param target
	 *            The target dao.
	 */
	public CacheResourceDao(IObjectManager target) {
		setTarget(target);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.orange.architecture.db.CacheDao#getKey(net.orange.architecture.vo
	 * .BaseValueObject)
	 */
	@Override
	protected Object getKey(BaseValueObject b0) throws Exception {
		Resource resource = (Resource) b0;
		return (resource != null) ? resource.getResource() : null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.db.CacheDao#getCache()
	 */
	public Map<Object, Object> getCache() {
		return cache;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.db.CacheDao#setCache(java.util.Map)
	 */
	public void setCache(Map<Object, Object> cache) {
		CacheResourceDao.cache = cache;
	}

}
